#include "ACtg.h"
long double ACtg::calcul(long double aux1)
{
    return Minus::calcul(M_PI_2, atanl(aux1));

}
long double ACtg::calcul()
{
    if (!fStang)
        exit(1);
    return calcul(fStang->calcul());
}

char *ACtg::derivare()
{
    char *aux1, *aux2, *aux, *aux00, *aux01, *aux02, *aux03;

    if (!fStang)
        exit(1);

    aux1 = fStang->derivare();
    aux2 = fStang->toString();

    aux00 = Putere::concatTermeni(aux2, "2");
    aux01 = Minus::concatTermeni("1", aux00);
    aux02 = Putere::concatTermeni(aux01, "0.5");
    aux03 = Impartit::concatTermeni(aux1, aux02);
    aux = Minus::concatTermeni(0, aux03);
    delete aux1; delete aux2; delete aux00; delete aux01; delete aux02; delete aux03;

    return aux;
}

long double ACtg::calculDerivata()
{
    if (!fStang)
        exit(1);

    return Minus::calcul(0, Impartit::calcul(fStang->calculDerivata(), Putere::calcul(
            Minus::calcul(1, Putere::calcul(fStang->calcul(), 2)), 0.5)));
}

char *ACtg::toString()
{
    char *aux, *aux1;
    int nrP;

    if (!fStang)
        exit(1);
    aux1 = fStang->toString();

    aux = concatTermeni(aux1);
    delete aux1;
    return aux;
}

char *ACtg::concatTermeni(char *aux1)
{
    char *aux;
    int nrP;

    nrP = aux1[0] == '(' ? 0 : 2;
    aux = new char[strlen(aux1) + 5 + nrP];

    strcpy(aux, "actg");
    if (nrP) strcat(aux, "(");
    strcat(aux, aux1);
    if (nrP) strcat(aux, ")");

    return aux;
}
